package com.vol.controller.sys;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.vol.entity.Result;
import com.vol.entity.UserInfo;
import com.vol.requestparams.QuanxianParams;
import com.vol.sys.RoleService;
import com.vol.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/role")
public class RoleController {
    @Autowired
    private UserContext userContext;
    @Autowired
    private RoleService roleService;

    @PostMapping("getUserChildRoles")
    public Result getUserChildRoles(){
        List<Map<String,Object>> listmap = roleService.getUserChildRoles(true);
        return Result.ok(listmap,null,null);
    }

    @PostMapping("getCurrentTreePermission")
    public Result getCurrentTreePermission() throws JsonProcessingException {
        Map<String,Object> resultMap = roleService.getCurrentTreePermission();
        return Result.ok(resultMap,null,null);
    }

    @PostMapping("getUserTreePermission")
    public Result getUserTreePermission(Integer roleId) throws JsonProcessingException {
        List<Map<String,Object>> menuMap = roleService.getUserTreePermission(roleId);
        return Result.ok(menuMap,null,null);
    }

    @PostMapping("SavePermission")
    public Result SavePermission(int roleId, @RequestBody List<QuanxianParams> listQx) throws JsonProcessingException {
        roleService.SavePermission(roleId,listQx);
        return Result.ok(null,null,"操作成功！");
    }

}
